package com.sinosoft.dsp.component.bpm.viewbean.activity.part;

import java.util.List;

import com.sinosoft.dsp.component.bpm.viewbean.BpmPrivilegeObject;
import com.sinosoft.dsp.component.bpm.viewbean.activity.BpmAbstractActivityPartEditViewBean;
import com.sinosoft.dsp.component.bpm.viewbean.activity.IBpmActivityPartEditViewBean;
import com.sinosoft.dsp.func.entity.setting.system.role.RoleEntity;
import com.sinosoft.dsp.func.service.setting.system.role.IRoleService;
import com.sinosoft.dsp.platform.components.portal.input.picklist.SinoPickListModel;
import com.sinosoft.dsp.platform.utils.SinoManagedBean;
import com.sinosoft.dsp.security.utils.PrivilegeType;
import com.sinosoft.dsp.system.core.exception.SinoException;
import com.sinosoft.dsp.system.to.IGenericTO;

public class BpmActivityPrivilegesViewBean extends
		BpmAbstractActivityPartEditViewBean implements
		IBpmActivityPartEditViewBean {

	private SinoPickListModel<BpmPrivilegeObject> model = new SinoPickListModel<BpmPrivilegeObject>();

	@SuppressWarnings("unchecked")
	@Override
	public void init(IGenericTO tos) throws SinoException {
		super.init(tos);

		IRoleService rs = SinoManagedBean.findBean("roleService");
		List<RoleEntity> roles = rs.findAll();
		if (roles != null) {
			for (RoleEntity re : roles) {
				BpmPrivilegeObject bp = new BpmPrivilegeObject();
				bp.setId(re.getRoleuuid());
				bp.setName(re.getRolename());
				bp.setType(PrivilegeType.DEFAULT_PRIVILEGE_TYPE.getKey());

				model.getSource().add(bp);
				
				//model.getTarget().add()
				//TODO
			}
		}
	}

	public void action(String type) {
		model.action(type);
	}

	public SinoPickListModel<BpmPrivilegeObject> getModel() {
		return model;
	}

	public void setModel(SinoPickListModel<BpmPrivilegeObject> model) {
		this.model = model;
	}

}
